from rest_framework import serializers
from .models import Project, Group, Satellite


class SatelliteSerializer(serializers.ModelSerializer):
    """
    卫星序列化器
    """
    class Meta:
        model = Satellite
        fields = ['id', 'name', 'description', 'created_at', 'updated_at']
        read_only_fields = ['created_at', 'updated_at']


class GroupSerializer(serializers.ModelSerializer):
    """
    组序列化器
    """
    satellites = SatelliteSerializer(many=True, read_only=True)
    
    class Meta:
        model = Group
        fields = ['id', 'name', 'description', 'satellites', 'created_at', 'updated_at']
        read_only_fields = ['created_at', 'updated_at']


class ProjectSerializer(serializers.ModelSerializer):
    """
    项目序列化器
    """
    groups = GroupSerializer(many=True, read_only=True)
    
    class Meta:
        model = Project
        fields = ['id', 'name', 'description', 'groups', 'created_at', 'updated_at']
        read_only_fields = ['created_at', 'updated_at']


class ProjectCreateUpdateSerializer(serializers.ModelSerializer):
    """
    项目创建和更新序列化器
    """
    class Meta:
        model = Project
        fields = ['name', 'description']


class GroupCreateUpdateSerializer(serializers.ModelSerializer):
    """
    组创建和更新序列化器
    """
    class Meta:
        model = Group
        fields = ['name', 'project', 'description']


class SatelliteCreateUpdateSerializer(serializers.ModelSerializer):
    """
    卫星创建和更新序列化器
    """
    class Meta:
        model = Satellite
        fields = ['name', 'group', 'description']